class Card
  CLUB = "club"
  DIAMOND = "diamond"
  HEART = "heart"
  SPADE = "spade"

  private

  def initialize(aSuit, aValue)
    @suit = aSuit
    @value = aValue
  end


  public

  def suitToInt
    temp = self.getSuit
    case temp
      when "spade"
        return 4
      when "heart"
        return 3
      when "diamond"
        return 2
      when "club"
        return 1
    end
  end

  def getSuit
    @suit
  end

  def getValue
    @value
  end

  def setSuit(suit)
    @suit = suit
  end

  def setValue(value)
    @value = value
  end

  def valueToString
    case @value
      when 2..9
        return @value.to_s
      when 10
        return "T"
      when 11
        return "J"
      when 12
        return "Q"
      when 13
        return "K"
      when 14
        return "A"
    end
  end

  def to_s
    string = valueToString
    "<"+"#@suit " + string+">"

  end

  def <=>(aCard)
    if aCard.getValue < self.getValue then
      return 1
    end
    if aCard.getValue > self.getValue then
      return -1
    end
    if aCard.getValue == self.getValue
      a =  aCard.suitToInt
      b =  self.suitToInt
      if a < b then
        return 1
      end
      if a > b then
        return -1
      end
      if a == b then
        return 0
      end
    end
  end

end


class CardDeck < Array

  private
  def initSuit(aSuit)
    arr = []
    13.times do |x|
      arr[x] = Card.new(aSuit, x+2)
    end
    return arr
  end

  def initialize
    d1 = initSuit("heart")
    d2 = initSuit("spade")
    d3 = initSuit("diamond")
    d4 = initSuit("club")
    d1.each do |x|
      self.push(x)
    end
    d2.each do |x|
      self.push(x)
    end
    d3.each do |x|
      self.push(x)
    end
    d4.each do |x|
      self.push(x)
    end

  end

  def swap(anIndex1, anIndex2)
    temp = self[anIndex1]
    temp.setValue(self[anIndex1].getValue)

    self[anIndex1] = self[anIndex2]
    self[anIndex1].setValue(self[anIndex2].getValue)

    self[anIndex2] = temp
    self[anIndex2].setValue(temp.getValue)

  end

  public

  def next
    temp = self.first
    self.delete_at(0)
    return temp
  end

  def shuffle
    26.times do
      swap(Random.new.rand(0..51), Random.new.rand(0..51))
    end
  end

  def to_s
    self.inject() { |x,y | x=x.to_s+" "+y.to_s; x  }
    end


end

class CardHand < Array

  def initialize

  end

  def getCards(aDeck)
    13.times do |x|
      self[x] = aDeck.next
    end

    13.times do |x|
      min = x
      i = x+1
      while i < 12 do
        if (self[min]<=>self[i]) == 1 then
          min = i
        end
        i +=1
      end
      if min != x
        temp = self[x]
        self[x] = self[min]
        self[min] = temp
      end
    end
    return self
  end

  def to_s()
    self.inject() { |x,y | x=x.to_s+" "+y.to_s; x  }
    end

end


class Bridge

  private
  def initialize
    @deck = CardDeck.new
    @deck.shuffle
    @west = CardHand.new.getCards(@deck)
    @north = CardHand.new.getCards(@deck)
    @east = CardHand.new.getCards(@deck)
    @south = CardHand.new.getCards(@deck)


  end

  public
  def getWest
    return @west
  end

  def getNorth
    return @north
  end

  def getEast
    return @east
  end

  def getSouth
    return @south
  end

end


br = Bridge.new
puts "West: #{br.getWest.to_s}"
puts
puts "North: #{br.getNorth.to_s}"
puts
puts "East: #{br.getEast.to_s}"
puts
puts "South: #{br.getSouth.to_s}"